home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / emsif24a.zip / TESTUTIL.C < prev    next >
C/C++ Source or Header  |  1991-11-15  |  36KB  |  769 lines

  1. /***************************************************************************
  2. *   TESTUTIL.C                                                             *
  3. *   MODULE:  TESTUTIL                                                      *
  4. *   OS:      DOS                                                           *
  5. *   VERSION: 1.0                                                           *
  6. *   DATE:    11/15/91                                                      *
  7. *                                                                          *
  8. *   Copyright (c) 1991 James W. Birdsall. All Rights Reserved.             *
  9. *                                                                          *
  10. *   Requires testutil.h to compile.                                        *
  11. *   Compiles under Borland C++ 2.0, TC 2.0, or MSC 6.00A.                  *
  12. *                                                                          *
  13. *   This file contains various utility functions used to fill and check    *
  14. *   blocks of memory and perform other basic services. Many are coded in   *
  15. *   in-line assembly language to improve speed. The in-line assembly is    *
  16. *   compatible with both Turbo/Borland C[++] and MSC 6.00A. If your        *
  17. *   compiler does not support in-line assembly, or your compiler requires  *
  18. *   an external assembler which you do not have, or you simply do not wish *
  19. *   to use the in-line assembly code, the functions also contain C code    *
  20. *   versions. The C code versions are the default; in order to use the     *
  21. *   in-line assembly, you must define the symbol INLINE_ASM when           *
  22. *   compiling.                                                             *
  23. *                                                                          *
  24. ***************************************************************************/
  25.  
  26. /*
  27. ** system includes <>
  28. */
  29.  
  30. #include <string.h>
  31. #include <dos.h>
  32.  
  33.  
  34. /*
  35. ** custom includes ""
  36. */
  37.  
  38. #include "testutil.h"
  39.  
  40.  
  41. /*
  42. ** local #defines
  43. */
  44.  
  45. /*
  46. ** misc: copyright strings, version macros, etc.
  47. */
  48.  
  49. /*
  50. ** typedefs
  51. */
  52.  
  53. /*
  54. ** global variables
  55. */
  56.  
  57. /*
  58. ** static globals
  59. */
  60.  
  61. /*
  62. ** function prototypes
  63. */
  64.  
  65. /*
  66. ** functions
  67. */
  68.  
  69. /***************************************************************************
  70. *   FUNCTION: FARMEMCHECK                                                  *
  71. *                                                                          *
  72. *   DESCRIPTION:                                                           *
  73. *                                                                          *
  74. *       This function scans a block of memory looking for bytes which do   *
  75. *       not match checkchar.                                               *
  76. *                                                                          *
  77. *   ENTRY:                                                                 *
  78. *                                                                          *
  79. *       buffer    - pointer to block of memory to scan                     *
  80. *       len       - length of block                                        *
  81. *       checkchar - value which should be matched                          *
  82. *                                                                          *
  83. *   EXIT:                                                                  *
  84. *                                                                          *
  85. *       Returns 0 if all bytes match, nonzero if mismatch found.           *
  86. *                                                                          *
  87. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  88. *                                                                          *
  89. ***************************************************************************/
  90. int farmemcheck(unsigned char far *buffer, unsigned int len,
  91.                                                        unsigned char checkchar)
  92. {
  93.     int retval = 0;
  94.     unsigned char huge *temp;
  95.  
  96.     /* normalize far pointer and turn into huge pointer */
  97.     temp = normptr(buffer);
  98.  
  99. #ifdef INLINE_ASM
  100.     ASM  push     bx                    /* preserve registers           */
  101.     ASM  push     cx
  102.     ASM  push     si
  103.     ASM  push     ds
  104.     ASM  lds      si, [temp]            /* load pointer into DS:SI      */
  105.     ASM  mov      cx, [len]             /* load length into CX          */
  106.     ASM  mov      bl, [checkchar]       /* load match value into BX     */
  107. looptop:
  108.     ASM  lodsb                          /* load next byte into AL       */
  109.     ASM  cmp      al, bl                /* test against BL              */
  110.     ASM  jne      nomatch               /* if not equal, exit loop      */
  111.     ASM  loop     looptop               /* otherwise loop               */
  112.     ASM  jmp      match
  113. nomatch:
  114.     ASM  mov      WORD PTR [retval], 1  /* return nonzero on mismatch   */
  115. match:
  116.     ASM  pop      ds                    /* restore register values      */
  117.     ASM  pop      si
  118.     ASM  pop      cx
  119.     ASM  pop      bx
  120. #else
  121.     for (; len; len--, temp++)          /* do the same thing in C       */
  122.     {
  123.         if (*temp != checkchar)
  124.         {
  125.             retval = 1;
  126.             break;
  127.         }
  128.     }
  129. #endif
  130.  
  131.     return retval;
  132. } /* end of farmemcheck() */
  133.  
  134.  
  135. /***************************************************************************
  136. *   FUNCTION: LFARMEMCHECK                                                 *
  137. *                                                                          *
  138. *   DESCRIPTION:                                                           *
  139. *                                                                          *
  140. *       This function scans a block of memory longer than 64K looking for  *
  141. *       bytes which do not match checkchar.                                *
  142. *                                                                          *
  143. *   ENTRY:                                                                 *
  144. *                                                                          *
  145. *       buffer    - pointer to block of memory to scan                     *
  146. *       len       - length of block                                        *
  147. *       checkchar - value which should be matched                          *
  148. *                                                                          *
  149. *   EXIT:                                                                  *
  150. *                                                                          *
  151. *       Returns 0 if all bytes match, nonzero if mismatch found.           *
  152. *                                                                          *
  153. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  154. *                                                                          *
  155. ***************************************************************************/
  156. int lfarmemcheck(unsigned char far *buffer, unsigned long len,
  157.                                                        unsigned char checkchar)
  158. {
  159.     int retval;
  160.     unsigned int copylen;
  161.     unsigned char huge *temp;
  162.  
  163.     /* normalize far pointer and turn into huge pointer */
  164.     temp = normptr(buffer);
  165.  
  166.     while (len > 0L)
  167.     {
  168.         copylen = ((len > 65000L) ? 65000U : (unsigned int) len);
  169.         if ((retval = farmemcheck((void far *) temp, copylen, checkchar)) != 0)
  170.         {
  171.             return retval;
  172.         }
  173.         temp = normptr((unsigned char far *)(temp + copylen));
  174.         len -= copylen;
  175.     }
  176.  
  177.     return retval;
  178. } /* end of lfarmemcheck() */
  179.  
  180.  
  181. /***************************************************************************
  182. *   FUNCTION: LFMEMCMP                                                     *
  183. *                                                                          *
  184. *   DESCRIPTION:                                                           *
  185. *                                                                          *
  186. *       Compares two regions of memory longer than 64K.